/*
 * @lc app=leetcode.cn id=1394 lang=typescript
 *
 * [1394] 找出数组中的幸运数
 */

// @lc code=start
function findLucky(arr: number[]): number {
    const cache = new Map<number, number>();
    arr.forEach((i) => {
        cache.set(i, (cache.get(i) || 0) + 1);
    });
    let count = -1;
    for (const [key, value] of cache.entries()) {
        if (key === value && value > count) count = value;
    }
    return count;
}
// @lc code=end
